package com.fly.common.core.init.util

import cn.hutool.crypto.SecureUtil
import cn.hutool.crypto.symmetric.AES
import cn.hutool.crypto.symmetric.SymmetricAlgorithm
import cn.hutool.crypto.symmetric.SymmetricCrypto
import com.fly.common.core.init.base.BaseResult

/**
 * @author  fly
 * @date  2021/5/19 15:48
 * @version 1.0
 */

var key: ByteArray? = SecureUtil.generateKey(SymmetricAlgorithm.AES.value).encoded
var aes = SymmetricCrypto(SymmetricAlgorithm.AES, key)

/**
 * 加密字符串
 */
fun String.encrypt(): String = aes.encryptHex(this)

/**
 * 解密字符串
 */
fun String.decrypt(): String = aes.decryptStr(this)

/**
 * 获取返回结果
 */
fun Any.getBaseResult(desc: String): BaseResult = BaseResult(result = this, desc = desc)